package Socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;


public class Client3 {
    private Socket socket;
    public Client3(){
        try {
            System.out.println("正在链接服务端...");
            socket=new Socket("localhost",8080);
            System.out.println("服务端已链接...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            OutputStream out=socket.getOutputStream();
            String line="你好服务端！";
            byte[] data = line.getBytes(StandardCharsets.UTF_8);
            out.write(data.length);
            out.write(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Client3 client=new Client3();
        client.start();

    }

}
